package action;

import bean.Position;
import com.opensymphony.xwork2.Action;

import dao.PositionDAO;
import dao.TPositionDAOImpl;
import tools.HibernateSessionFactory;

import java.util.List;

public class PositionAction implements Action {
    private PositionDAO positionDAO = new TPositionDAOImpl(HibernateSessionFactory.getSession());
    private Position position;
    private List<Position> positions;

    public Position getPosition() {
        return position;
    }

    public void setPosition(Position position) {
        this.position = position;
    }

    public List<Position> getPositions() {
        return positions;
    }

    @Override
    public String execute() throws Exception {
        positions = positionDAO.queryAll();
        return SUCCESS;
    }

    public String add() {
        return positionDAO.add(position) ? "add" : null;
    }

    public String edit() {
        position = positionDAO.query(position.getPositionId());
        return "edit";
    }

    public String modify() {
        return positionDAO.edit(position) ? "modify" : null;
    }

    public String remove() {
        return positionDAO.remove(position.getPositionId()) ? "remove" : null;
    }
}
